import { AxiosResponse } from 'axios';
import { track } from '..';

export const axiosInterceptors = (response: AxiosResponse) => {
  if (!response.config.url) return response;
  const { data, headers: responseHeaders, config } = response;
  const log_id = responseHeaders?.['x-tt-logid'];
  track?.({
    log_id,
    api_path: response.config.url,
    response_header: responseHeaders,
    request_header: config.headers,
    request_query: config.params,
    request_body: config.data,
    response_body: data,
  });
  return response;
};
